from django.conf.urls.defaults import *
from django.conf import settings
from django.views.generic import create_update
from django.views.generic import list_detail
from core.models import *
from core.views import *

import django.contrib.auth.views


# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()




params_novo_fraccao = {
    'model' : Fraccoes,
    'post_save_redirect' : '/fraccoes/',
}

params_apagar_fraccao = {
    'model' : Fraccoes,
    'post_delete_redirect' : '/fraccoes/',
}

params_novo_fornecedor = {
    'model' : Fornecedores,
    'post_save_redirect' : '/fornecedores/',
}

params_apagar_fornecedor = {
    'model' : Fornecedores,
    'post_delete_redirect' : '/fornecedores/',
}

params_novo_despesa = {
    'model' : Despesas,
    'post_save_redirect' : '/despesas/',
}

params_apagar_despesa = {
    'model' : Despesas,
    'post_delete_redirect' : '/despesas/',
}

params_novo_receita = {
    'model' : Receitas,
    'post_save_redirect' : '/receitas/'
    ,
}

params_apagar_receita = {
    'model' : Receitas,
    'post_delete_redirect' : '/receitas/',
}


params_lista_despesas = {
    'queryset' : Despesas.objects.all(),
    #'queryset' : Despesas.objects.count(), 
}

params_novo_condomino = {
    'model' : Condominos,
    'post_save_redirect' : '/condominos/',
}

params_apagar_condomino = {
    'model' : Condominos,
    'post_delete_redirect' : '/condominos/',
}
        
        

urlpatterns = patterns('',
    # Uncomment the next line to enable the admin:
    # (r'^admin/', include(admin.site.urls)),
    (r'^admin/(.*)', admin.site.root),
    #('^$', 'django.views.generic.simple.direct_to_template',
    # {'template': 'home.html'}),
    
    ('^$', 'core.views.mainPage'),
    
    ('^login/$', 'django.contrib.auth.views.login'),
    ('^logout/$', 'django.contrib.auth.views.logout'),
    #Fraccoes
    (r'fraccoes/novo/$', create_update.create_object, params_novo_fraccao, 'novo_fraccao'),
    (r'fraccoes/$', list_detail.object_list, { 'queryset' : Fraccoes.objects.all() }, 'lista_fraccoes'),
    #(r'fraccoes/(?P<object_id>\d+)/$', list_detail.object_detail, { 'queryset' : Fraccoes.objects.all() }, 'ver_fraccao'),
    (r'fraccoes/(?P<object_id>\d+)/editar/$', create_update.update_object, params_novo_fraccao, 'editar_fraccao'),
    (r'fraccoes/(?P<object_id>\d+)/apagar/$', create_update.delete_object, params_apagar_fraccao, 'apagar_fraccao'),
    #Fornecedores
    (r'fornecedores/novo/$', create_update.create_object, params_novo_fornecedor, 'novo_fornecedor'),
    (r'fornecedores/$', list_detail.object_list, { 'queryset' : Fornecedores.objects.all() }, 'lista_fornecedores'),
    #(r'fornecedores/(?P<object_id>\d+)/$', list_detail.object_detail, { 'queryset' : Fornecedores.objects.all() }, 'ver_fornecedor'),
    (r'fornecedores/(?P<object_id>\d+)/editar/$', create_update.update_object, params_novo_fornecedor, 'editar_fornecedor'),
    (r'fornecedores/(?P<object_id>\d+)/apagar/$', create_update.delete_object, params_apagar_fornecedor, 'apagar_fornecedor'),
    #Despesas
    (r'despesas/novo/$', create_update.create_object, params_novo_despesa, 'novo_despesa'),
    (r'despesas/$', 'core.views.listaDespesas'),
    #(r'despesas/(?P<object_id>\d+)/$', list_detail.object_detail, { 'queryset' : Despesas.objects.all() }, 'ver_despesa'),
    (r'despesas/(?P<object_id>\d+)/editar/$', create_update.update_object, params_novo_despesa, 'editar_despesa'),
    (r'despesas/(?P<object_id>\d+)/apagar/$', create_update.delete_object, params_apagar_despesa, 'apagar_despesa'),
    #Receitas
    (r'receitas/novo/$', create_update.create_object, params_novo_receita, 'novo_receita'),
    (r'receitas/$', 'core.views.listaReceitas'),
    (r'receitas/(?P<object_id>\d+)/$', list_detail.object_detail, { 'queryset' : Receitas.objects.all() }, 'ver_receita'),
    (r'receitas/(?P<object_id>\d+)/editar/$', create_update.update_object, params_novo_receita, 'editar_receita'),
    (r'receitas/(?P<object_id>\d+)/apagar/$', create_update.delete_object, params_apagar_receita, 'apagar_receita'),
    #Saldo
    (r'saldo/$', 'core.views.saldo'),
    #meusPagamentos
    (r'meusPagamentos/$', 'core.views.meusPagamentos'),
    (r'condominos/$', list_detail.object_list, { 'queryset' : Condominos.objects.all() }, 'lista_condominos'),
    (r'condominos/novo/$', create_update.create_object, params_novo_condomino, 'novo_condomino'),
    #(r'condominos/(?P<object_id>\d+)/$', list_detail.object_detail, { 'queryset' : Condominos.objects.all() }, 'ver_condomino'),
    (r'condominos/(?P<object_id>\d+)/editar/$', create_update.update_object, params_novo_condomino, 'editar_condomino'),
    (r'condominos/(?P<object_id>\d+)/apagar/$', create_update.delete_object, params_apagar_condomino, 'apagar_condomino'),


    
    url(r'^password/alterar/$', 'django.contrib.auth.views.password_change',
        {'template_name': 'alterarPassword.html'},
        name='password_change'),
        
    url(r'^password/change/done/$',
        'django.contrib.auth.views.password_change_done',
        {'template_name': 'alterarPassword-done.html'},
        name='password_change_done'),  
        
    url(r'^password/reset/$', 'django.contrib.auth.views.password_reset',
        {'template_name': 'recuperarPassword.html'},
        name='password_reset'),    

    (r'^password_reset/$', 'django.contrib.auth.views.password_reset'),
    (r'^password_reset/done/$', 'django.contrib.auth.views.password_reset_done'),
    (r'^reset/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$', 'django.contrib.auth.views.password_reset_confirm'),
    (r'^reset/done/$', 'django.contrib.auth.views.password_reset_complete'),

    (r'', include('upload.urls')),


    
)
"""
if settings.DEBUG:
    urlpatterns += patterns('',
        (r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}),
    )
"""
